package com.marry.web;

import com.marry.entity.Invitation;
import com.marry.model.Result;
import com.marry.repository.InvitationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.util.List;

/**
 * 接口
 */
@RestController
@RequestMapping("/sys/marry")
public class MarryController {

    @Autowired
    private InvitationRepository invitationRepository;

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(Invitation entity) {
        invitationRepository.saveAndFlush(entity);
        return Result.ok("保存成功");
    }

    /**
     * 获取
     */
    @PostMapping("/get")
    public Result get() {
        List<Invitation> list = invitationRepository.findAll();
        if(list!=null&&list.size()!=0){
            return Result.ok(list.get(0));
        }
        return Result.error();
    }

}
